package edu.map.aamas.gui;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import edu.map.aamas.gui.tablelayout.TableLayout;

public class SliderPanel extends JPanel implements ChangeListener {
	private FloatJSlider slider;
	private JLabel lbl;
	public SliderPanel(String name, double val, double min, double max) {
		setLayout(new TableLayout(new double[] {80, TableLayout.FILL, 50}, new double[] {32}));
		add(new JLabel(name+":", JLabel.RIGHT), "0,0");
		slider = new FloatJSlider((float)min, (float)max, (float)val);
		add(slider, "1,0");
		slider.addChangeListener(this);
		lbl = new JLabel(""+(float)val);
		add(lbl, "2,0");
	}
	
	public void sliderUpdated(float value) {
		lbl.setText(""+slider.getFloatValue());
	}

	public void stateChanged(ChangeEvent e) {
		sliderUpdated(slider.getFloatValue());		
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("testing...");
		frame.getContentPane().add(new SliderPanel("K1", 0.3, -50, 50));
		frame.setSize(200, 30);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
}
